<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>函数默认值和剩余参数.html</title>
</head>
<body>
<script type="text/javascript">
    //ES5下给默认值
    function add5(a,b){
        a = a || 10;
        b = b || 10;
        return a+b;
    }
    //ES6下给默认值,这里的默认值还可以是一个函数表达式
    function add6(a=10,b=20){
        return a+b;
    }
    function add62(a = 10,b = getVal(5)){
        return a + b;
    }
    function getVal(val) {
        return val + 10;
    }
    console.log(add5());
    console.log(add6());
    console.log(add62());
    //==========================================================
    //ES6剩余参数，就类似与Java中的可变参数，不过ES6中就是代替了函数中隐含传递arguments
    function argDemo(a,b,c){
        for (let i = 0; i < arguments.length ; i++){
            console.log(arguments[i]);
        }
    }
    function argDemo2(a,...args){
        console.log(args);
    }
    argDemo(1,2,3);
    argDemo2(1,2,3,4,5,6,7);
</script>
</body>
</html>